/*
 * The MIT License
 *
 * Copyright 2011 Edwin Bratini <edwin.bratini@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * RegistroEdicionAntNeonatal.java
 *
 * Created on Nov 15, 2011, 5:05:40 PM
 */
package org.salvador_dali.psychsys.ui;

import java.math.BigDecimal;
import javax.swing.JOptionPane;
import org.salvador_dali.psychsys.model.entities.AntNeonatal;

/**
 *
 * @author Edwin Bratini <edwin.bratini@gmail.com>
 */
public class RegistroEdicionAntNeonatal extends javax.swing.JDialog {

    private RegistroEdicionModo modo = RegistroEdicionModo.REGISTRO;
    private AntNeonatal antNeonatal;
    private AntNeonatal anEditar;

    /** Creates new form RegistroEdicionAntNeonatal */
    public RegistroEdicionAntNeonatal(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public AntNeonatal getAntNeonatal() {
        return antNeonatal;
    }

    public void setAntNeonatal(AntNeonatal antNeonatal) {
        this.antNeonatal = antNeonatal;
    }

    public RegistroEdicionModo getModo() {
        return modo;
    }

    public void setModo(RegistroEdicionModo modo) {
        this.modo = modo;
    }

    public AntNeonatal getAnEditar() {
        return anEditar;
    }

    public void setAnEditar(AntNeonatal anEditar) {
        this.anEditar = anEditar;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgrLloro = new javax.swing.ButtonGroup();
        bgrAsistenciaMedica = new javax.swing.ButtonGroup();
        bgrColaboracion = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        lblTipoParto = new javax.swing.JLabel();
        cmbTipoParto = new javax.swing.JComboBox();
        lblPeso = new javax.swing.JLabel();
        lblLloro = new javax.swing.JLabel();
        rbnLloroSi = new javax.swing.JRadioButton();
        rbnLloroNo = new javax.swing.JRadioButton();
        lblAsistenciaMedica = new javax.swing.JLabel();
        rbnAsisMedSi = new javax.swing.JRadioButton();
        rbnAsisMedNo = new javax.swing.JRadioButton();
        lblColaboracion = new javax.swing.JLabel();
        rbnColSi = new javax.swing.JRadioButton();
        rbnColNo = new javax.swing.JRadioButton();
        lblEstadoGralNinio = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaEstadoGralNinio = new javax.swing.JTextArea();
        ftfPeso = new javax.swing.JFormattedTextField();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registrar Antecedentes Neonatal");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblTipoParto.setText("Tipo de Parto");

        cmbTipoParto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Prematuro", "Termino" }));

        lblPeso.setText("Peso");

        lblLloro.setText("Lloro");

        bgrLloro.add(rbnLloroSi);
        rbnLloroSi.setSelected(true);
        rbnLloroSi.setText("Si");

        bgrLloro.add(rbnLloroNo);
        rbnLloroNo.setText("No");

        lblAsistenciaMedica.setText("Asistencia Medica");

        bgrAsistenciaMedica.add(rbnAsisMedSi);
        rbnAsisMedSi.setSelected(true);
        rbnAsisMedSi.setText("Si");

        bgrAsistenciaMedica.add(rbnAsisMedNo);
        rbnAsisMedNo.setText("No");

        lblColaboracion.setText("Colaboracion");

        bgrColaboracion.add(rbnColSi);
        rbnColSi.setSelected(true);
        rbnColSi.setText("Si");

        bgrColaboracion.add(rbnColNo);
        rbnColNo.setText("No");

        lblEstadoGralNinio.setText("Estado General del Ninño(a)");

        txaEstadoGralNinio.setColumns(20);
        txaEstadoGralNinio.setLineWrap(true);
        txaEstadoGralNinio.setRows(5);
        txaEstadoGralNinio.setWrapStyleWord(true);
        jScrollPane1.setViewportView(txaEstadoGralNinio);

        ftfPeso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblPeso)
                    .addComponent(lblTipoParto)
                    .addComponent(lblColaboracion)
                    .addComponent(lblAsistenciaMedica)
                    .addComponent(lblLloro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbnColSi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rbnColNo))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbnAsisMedSi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rbnAsisMedNo))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(ftfPeso, 0, 0, Short.MAX_VALUE)
                        .addComponent(cmbTipoParto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbnLloroSi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rbnLloroNo)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(lblEstadoGralNinio))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTipoParto)
                    .addComponent(cmbTipoParto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEstadoGralNinio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPeso)
                            .addComponent(ftfPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblLloro)
                            .addComponent(rbnLloroSi)
                            .addComponent(rbnLloroNo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblAsistenciaMedica)
                            .addComponent(rbnAsisMedSi)
                            .addComponent(rbnAsisMedNo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblColaboracion)
                            .addComponent(rbnColSi)
                            .addComponent(rbnColNo)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        statusMessageLabel.setForeground(new java.awt.Color(0, 153, 51));
        statusMessageLabel.setText("Antecedentes neonatal registrado exitosamente.");

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/circle progress bar 20x20.png"))); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 204, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel))
                .addContainerGap())
        );

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnAceptar)
                        .addGap(10, 10, 10)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        statusMessageLabel.setVisible(false);
        statusAnimationLabel.setVisible(false);
    }//GEN-LAST:event_formWindowOpened

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        ProgressCircle pc = new ProgressCircle(statusAnimationLabel);
        pc.start();
        String trabajoCompletoMensaje = "Antecedentes Neonatal registrado exitosamente.";

        // si todo esta bien
        statusMessageLabel.setVisible(false);

        if (modo != null && modo.equals(RegistroEdicionModo.REGISTRO)) {
            antNeonatal = new AntNeonatal(null, cmbTipoParto.getSelectedItem().toString(), rbnAsisMedSi.isSelected() ? 'S' : 'N');
            antNeonatal.setAnePeso(!ftfPeso.getText().isEmpty() ? BigDecimal.valueOf(Double.parseDouble(ftfPeso.getText())) : null);
            antNeonatal.setAneLloro(rbnLloroSi.isSelected() ? 'S' : 'N');
            antNeonatal.setAneColaboracion(rbnColSi.isSelected() ? 'S' : 'N');
            antNeonatal.setAneEstadoGeneral(!txaEstadoGralNinio.getText().isEmpty() ? txaEstadoGralNinio.getText() : null);

            // se registra cuando le dan aceptar en ventana de historia clinica
        } else if (modo != null && modo.equals(RegistroEdicionModo.EDICION)) {
            anEditar.setAneTipoParto(cmbTipoParto.getSelectedItem().toString());
            anEditar.setAneAsistenciaMedica(rbnAsisMedSi.isSelected() ? 'S' : 'N');

            anEditar.setAnePeso(!ftfPeso.getText().isEmpty() ? BigDecimal.valueOf(Double.parseDouble(ftfPeso.getText())) : null);
            anEditar.setAneLloro(rbnLloroSi.isSelected() ? 'S' : 'N');
            anEditar.setAneColaboracion(rbnColSi.isSelected() ? 'S' : 'N');
            anEditar.setAneEstadoGeneral(!txaEstadoGralNinio.getText().isEmpty() ? txaEstadoGralNinio.getText() : null);

            // se actualiza cuando le dan aceptar en ventana de historia clinica
        }

        pc.stop();
        JOptionPane.showMessageDialog(this, trabajoCompletoMensaje, "Antecedentes Neonatal", JOptionPane.INFORMATION_MESSAGE);
        this.dispose();
    }//GEN-LAST:event_btnAceptarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RegistroEdicionAntNeonatal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RegistroEdicionAntNeonatal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RegistroEdicionAntNeonatal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RegistroEdicionAntNeonatal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                RegistroEdicionAntNeonatal dialog = new RegistroEdicionAntNeonatal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgrAsistenciaMedica;
    private javax.swing.ButtonGroup bgrColaboracion;
    private javax.swing.ButtonGroup bgrLloro;
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cmbTipoParto;
    private javax.swing.JFormattedTextField ftfPeso;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAsistenciaMedica;
    private javax.swing.JLabel lblColaboracion;
    private javax.swing.JLabel lblEstadoGralNinio;
    private javax.swing.JLabel lblLloro;
    private javax.swing.JLabel lblPeso;
    private javax.swing.JLabel lblTipoParto;
    private javax.swing.JRadioButton rbnAsisMedNo;
    private javax.swing.JRadioButton rbnAsisMedSi;
    private javax.swing.JRadioButton rbnColNo;
    private javax.swing.JRadioButton rbnColSi;
    private javax.swing.JRadioButton rbnLloroNo;
    private javax.swing.JRadioButton rbnLloroSi;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextArea txaEstadoGralNinio;
    // End of variables declaration//GEN-END:variables
}
